//
//  InfraredArmView.swift
//  SBSafetyApp
//
//  Created by Lina on 2022/11/15.
//

import Foundation
import UIKit

class InfraredArmView: ElecCreateScrollView {
    let tjrqTF = DateEffect()
    let val0TF = DateEffect()
//    let val1TF = SignEffect()
    let val5TF = LabelEffect(withEnable: false)
    let val7TF = LabelEffect(withEnable: false)
    let val2TF = DateEffect()
//    let val3TF = SignEffect()
    let val6TF = LabelEffect(withEnable: false)
    let val8TF = LabelEffect(withEnable: false)
    let val4TV = TextViewEffect()
    
    func registerField(withValidator validator: Validator) {
        validator.registerField(tjrqTF.valueL, rules: [RequiredRule(message: tjrqTF.placeholder)])
//        validator.registerField(val0TF.valueL, rules: [RequiredRule(message: val0TF.placeholder)])
//        validator.registerField(val1TF, rules: [RequiredRule(message: val1TF.placeholder)])
//        validator.registerField(val2TF.valueL, rules: [RequiredRule(message: val2TF.placeholder)])
//        validator.registerField(val3TF, rules: [RequiredRule(message: val3TF.placeholder)])
//        validator.registerField(val4TV.valueTV, rules: [RequiredRule(message: val4TV.placeholder)])
    }
    
    func updateHistory(withM model: StandingBookModal) {
        tjrqTF.value = Date.momentDate(model.tjrq ?? "")
        val0TF.value = model.attrValue0
//        val1TF.urlStr = model.attrValue1
        val5TF.value = model.attrValue5
        val7TF.value = model.attrValue7
        val2TF.value = model.attrValue2
//        val3TF.urlStr = model.attrValue3
        val6TF.value = model.attrValue6
        val8TF.value = model.attrValue8
        val4TV.value = model.attrValue4

//        val1TF.ctl.isHidden = false
//        val3TF.ctl.isHidden = false
//        
//        val1TF.isEdited = true
//        val3TF.isEdited = true
    }
    
    override func setupUI() {
        super.setupUI()
        
        titleL.text = "红外线布、撤防记录"
        subTitleL.text = "布、撤防记录"
        
        tjrqTF.placeholder = "日期"
        tjrqTF.value = Date.todayDateCN()
        tjrqTF.maximumDate = Date()
        addSubview(tjrqTF)
        tjrqTF.snp.makeConstraints { (make) -> Void in
            make.top.equalTo(subTitleL.snp.bottom).offset(18)
            make.centerX.equalTo(self.snp.centerX)
            make.height.equalTo(56)
            make.width.equalTo(ScreenWidth - 20)
        }
        
        val0TF.placeholder = "撤防时间"
        val0TF.dateMode = .time
        addSubview(val0TF)
        val0TF.snp.makeConstraints { (make) -> Void in
            make.top.equalTo(tjrqTF.snp.bottom).offset(10)
            make.centerX.equalTo(self.snp.centerX)
            make.height.equalTo(56)
            make.width.equalTo(ScreenWidth - 20)
        }
                
//        val1TF.placeholder = "撤防人签名"
//        addSubview(val1TF)
//        val1TF.snp.makeConstraints { (make) -> Void in
//            make.top.equalTo(val0TF.snp.bottom).offset(10)
//            make.centerX.equalTo(self.snp.centerX)
//            make.height.equalTo(56)
//            make.width.equalTo(ScreenWidth - 20)
//        }
        val5TF.placeholder = "撤防人"
        addSubview(val5TF)
        val5TF.snp.makeConstraints { (make) -> Void in
            make.top.equalTo(val0TF.snp.bottom).offset(10)
            make.centerX.equalTo(self.snp.centerX)
            make.height.equalTo(56)
            make.width.equalTo(ScreenWidth - 20)
        }
        
        val7TF.placeholder = "撤防人"
        addSubview(val7TF)
        val7TF.snp.makeConstraints { (make) -> Void in
            make.top.equalTo(val5TF.snp.bottom).offset(10)
            make.centerX.equalTo(self.snp.centerX)
            make.height.equalTo(56)
            make.width.equalTo(ScreenWidth - 20)
        }
                
        val2TF.placeholder = "布防时间"
        val2TF.dateMode = .time
        addSubview(val2TF)
        val2TF.snp.makeConstraints { (make) -> Void in
            make.top.equalTo(val7TF.snp.bottom).offset(10)
            make.centerX.equalTo(self.snp.centerX)
            make.height.equalTo(56)
            make.width.equalTo(ScreenWidth - 20)
        }
        
//        val3TF.placeholder = "布防人签名"
//        addSubview(val3TF)
//        val3TF.snp.makeConstraints { (make) -> Void in
//            make.top.equalTo(val2TF.snp.bottom).offset(10)
//            make.centerX.equalTo(self.snp.centerX)
//            make.height.equalTo(56)
//            make.width.equalTo(ScreenWidth - 20)
//        }
        val6TF.placeholder = "布防人A"
        addSubview(val6TF)
        val6TF.snp.makeConstraints { (make) -> Void in
            make.top.equalTo(val2TF.snp.bottom).offset(10)
            make.centerX.equalTo(self.snp.centerX)
            make.height.equalTo(56)
            make.width.equalTo(ScreenWidth - 20)
        }
        
        val8TF.placeholder = "布防人B"
        addSubview(val8TF)
        val8TF.snp.makeConstraints { (make) -> Void in
            make.top.equalTo(val6TF.snp.bottom).offset(10)
            make.centerX.equalTo(self.snp.centerX)
            make.height.equalTo(56)
            make.width.equalTo(ScreenWidth - 20)
        }
        
        val4TV.placeholder = "发现问题"
        addSubview(val4TV)
        val4TV.snp.makeConstraints { (make) -> Void in
            make.top.equalTo(val8TF.snp.bottom).offset(10)
            make.centerX.equalTo(self.snp.centerX)
            make.height.equalTo(100)
            make.width.equalTo(ScreenWidth - 20)
        }
        
        addSubview(saveBtn)
        saveBtn.snp.makeConstraints { (make) -> Void in
            make.top.equalTo(val4TV.snp.bottom).offset(32)
            make.left.equalToSuperview().offset(10)
            make.height.equalTo(50)
            make.width.equalTo(90)
        }
        
        addSubview(submitBtn)
        submitBtn.snp.makeConstraints { (make) -> Void in
            make.height.equalTo(saveBtn.snp.height)
            make.centerY.equalTo(saveBtn.snp.centerY)
            make.left.equalTo(saveBtn.snp.right).offset(10)
            make.width.equalTo(ScreenWidth - 120)
        }
        
        let bottomIV = UIImageView(image: UIImage(named: "elec_bottom"))
        addSubview(bottomIV)
        bottomIV.snp.makeConstraints { (make) -> Void in
            make.centerX.equalTo(self.snp.centerX)
            make.top.equalTo(submitBtn.snp.bottom).offset(20)
            make.bottom.equalTo(self.snp.bottom).offset(-16)
            make.height.equalTo(24)
        }
    }
}
